package poj3176;

import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] num = new int[n];
		int[] t = new int[n];
		
		for(int i=0; i<n; i++)
		{
			for(int j=0; j<=i; j++)
			{
				t[j] = sc.nextInt();
			}
			
			for(int j=i; j>-1; j--)
			{
				if(j == 0)
					num[0] += t[0];
				else
					num[j] = (num[j-1]>num[j]?num[j-1]:num[j]) + t[j];
			}
		}
		
		int max = 0;
		for(int a : num)
		{
			if(a > max)
				max = a;
		}
		
		System.out.println(max);
	}
}
